#include "ProcessPool.hpp"

int main()
{
    ProcessPool pp;
    pp.InitProcessPool([](int fd)
                       {
         while(1)
        {
            int code = 0;
            ssize_t n = read(fd, &code, sizeof(code));
            if(n == sizeof(code))
            {
                std::cout << "子进程被唤醒:" << getpid() << std::endl;
                if(code >= 0 && code < tasks.size())
                {
                    tasks[code]();
                }
                else
                {
                    std::cerr << "任务码错误:" << code << std::endl;
                }
            }
            else if(n == 0)
            {
                std::cout << "子进程应该退出了:" << getpid() << std::endl;
                break;
            }
            else
            {
                
            }
        } });
    pp.ControlSubProcess(10);
    pp.WaitSubProcess();
    return 0;
}